<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>酒店评论信息管理</title>
<%@include file="../../head.jsp"%>


</head>
<body>
	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="reviewRecord" formatter="renderReviewRecord">查看评论</th>
				<th field="reviewType" formatter="renderHotelExtType">评论的类型</th>
				<th field="reviewUrl">评论类型的网址</th>
				<th field="reviewCount">评论总数</th>
				<th field="reviewScore">评论的分数</th>
				<th field="reviewFullScore">评分的满分</th>
				<th field="reviewLevel">评分的级别</th>
				<th field="reviewRank">酒店排名</th>
				<th field="crawlerTime">抓取时间</th>
				<th field="crawlerSuccessCount">抓取成功次数</th>
				<th field="crawlerFailCount">抓取失败次数</th>
				<th field="crawlerStatus" formatter="renderCrawlerState">当前抓取的状态</th>
			</tr>
		</thead>
	</table>

	<div id="addHotelResourceInfoDialog"
		style="width: 200px; height: 180px; padding: 10px 20px"></div>

	<script type="text/javascript">
		var hotelExtType = {
			'1' : '到到',	
			'2' : 'tripadvisor',
			'3' : 'hotels',
			'4' : 'booking'
			
		};
		
		function renderHotelExtType(value, row, index) {
			return hotelExtType[value];
		};
		var crawlerState = {
				'1' : '等待抓取',
				'2' : '正在抓取中',
				'3' : '抓取成功',
				'4' : '抓取失败'
				
			};
			
			function renderCrawlerState(value, row, index) {
				return crawlerState[value];
			};
		//function renderImg(value, row, index){
			//return "<img src='${cpath}${upload_image_root}"+row.resourceImgPreffix+value+"' width='150' height='100'>";
	//	};
		
		function renderReviewRecord(value,row,index){
			var manager = "<a href='${cpath }/admin/hotel/review/record/vlist?reviewId="+row.reviewId+"&hotelId="+row.hotelId+"'>查看评论</a>";
			return manager;
		};
		$('#list_data')
				.datagrid(
						{
							title : '<a href=${cpath }/admin/dest/vlist>目的地</a>&gt&gt'+
									'<a href=${cpath }/admin/hotel/vlist?destId=${dest.destId}><c:out value="${dest.zhname}" escapeXml="true"/>酒店</a>&gt&gt<c:out value="${hotel.zhname}" escapeXml="true"/>',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 'auto',
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : true,
							url : '${cpath }/admin/hotel/review/list?hotelId=${hotel.hotelId}',
							remoteSort : false,
							idField : 'reviewId',
							singleSelect : true,//是否单选 
							pagination : false,//分页控件 
							rownumbers : true,//行号 
							toolbar : [{
										text : '添加酒店评论统计信息',
										iconCls : 'icon-add',
										handler : function() {
											var saveAction = cpath
													+ '/admin/hotel/review/save?hotelId=${hotel.hotelId}';
											var openAction = cpath
													+ '/admin/hotel/review/vsave';
													openAddHotelReviewDialog(
													'添加酒店评论统计信息', openAction,
													saveAction, addHotelReviewSuccess);
										}
									},'-',
									{
										text : '修改酒店评论统计信息',
										iconCls : 'icon-edit',
										handler : function() {
											var saveAction = cpath
													+ '/admin/hotel/review/update';
											var openAction = cpath
													+ '/admin/hotel/review/vupdate';
													openUpdateHotelReviewDialog(
													'修改酒店评论统计信息', openAction,
													saveAction,
													addHotelReviewSuccess,
													getSelectHotelReview);
										}	
									},'-',{
										text : '删除酒店评论统计',
										iconCls : 'icon-remove',
										handler : function() {
											var deleteAction = cpath
													+ '/admin/hotel/review/delete';
											deleteHotelReview(deleteAction, getSelectHotelReview);
										}
									},'-',{
										text : '刷新',
										iconCls : 'icon-reload',
										handler : function() {
											$('#list_data').datagrid('reload');
											save_status = false;
										}
									}]
						});
		</script>
		<script type="text/javascript">

			var url;
			var cpath = '${cpath}';
			function addHotelReviewSuccess() {
				$('#list_data').datagrid('reload'); // reload the user data
			}
			function getSelectHotelReview() {
				return $('#list_data').datagrid('getSelected');
			}
			function openAddHotelReviewDialog(dlgtitle, openAction, saveAction,
					successCallback) {
				
				$('#addHotelResourceInfoDialog').dialog({
					title : dlgtitle,
					width : 600,
					height : 350,
					closed : false,
					cache : false,
					resizable : true,
					href : openAction,
					modal : true,
					closed : true,
					buttons : [ {
						text : '保存',
						iconCls : "icon-ok",
						handler : function() {
							saveHotelBaseInfoForm(saveAction, successCallback);
						}
					}, {
						text : '取消',
						iconCls : "icon-cancel",
						handler : function() {
							$('#addHotelResourceInfoDialog').dialog('close');
						}
					} ]
				});
				$('#addHotelResourceInfoDialog').dialog('open');
			}

			function openUpdateHotelReviewDialog(dlgtitle, openAction, saveAction,
					successCallback,getSelectHotel) {
				//添加信息，需要是否有前置条件
				if (getSelectHotel) {
					var row = getSelectHotel();
					//没有选中行，则需要提示
					if (!row) {
						$.messager.alert("提示", "请选择一条酒店评论统计信息！", "info");
						return;
					} else {
						openAction += '?reviewId=' + row.reviewId;
					}
				}
				$('#addHotelResourceInfoDialog').dialog({
					title : dlgtitle,
					width : 600,
					height : 350,
					closed : false,
					cache : false,
					resizable : true,
					href : openAction,
					modal : true,
					closed : true,
					buttons : [ {
						text : '保存',
						iconCls : "icon-ok",
						handler : function() {
							saveHotelBaseInfoForm(saveAction, successCallback);
						}
					}, {
						text : '取消',
						iconCls : "icon-cancel",
						handler : function() {
							$('#addHotelResourceInfoDialog').dialog('close');
							$('#list_data').datagrid('clearSelections');
						}
					} ]
				});
				$('#addHotelResourceInfoDialog').dialog('open');
			}
			var save_status = false;
			function saveHotelBaseInfoForm(saveAction, successCallback) {
				if (save_status) {
					$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
					return;
				}
				save_status = true;
				$('#fm').form('submit', {
					url : saveAction,
					onSubmit : function() {
						var result =  $(this).form('validate');
						if (!result){
							save_status = false;
						}
						return result;
					},
					success : function(result) {
						var result = eval('(' + result + ')');
						if (result.resultCode !== '00000000') {
							$.messager.alert("错误", result.resultMsg, "error");
							$('#list_data').datagrid('clearSelections');
						} else {
							$.messager.alert("成功", result.resultMsg, "info");
							$('#addHotelResourceInfoDialog').dialog('close');
							if (successCallback) {
								successCallback();
							}
							$('#list_data').datagrid('clearSelections');
						}
						save_status = false;
					}
				});
			}
			function deleteHotelReview(deleteAction, getSelectHotelReview) {
				//添加信息，需要是否有前置条件
				if (getSelectHotelReview) {

					var row = getSelectHotelReview();
					//没有选中行，则需要提示
					if (!row) {
						$.messager.alert("提示", "请选择要删除的酒店评论统计信息！", "info");
						return;
					}
					if (row) {
						$.messager.confirm("提示", "确认要删除酒店评论统计信息吗？", function(r) {
							if (r) {
								$.post(deleteAction, row,
										function(result) {
											if (result.resultCode === '00000000') {
												$('#list_data').datagrid('reload'); // reload the user data
												$.messager.alert("提示",
														result.resultMsg, "info");
												$('#list_data').datagrid(
														'clearSelections');
											} else {
												$.messager.alert("错误",
														result.resultMsg, "error");
												$('#list_data').datagrid('clearSelections');
											}
										}, 'json');
							}
						});
					}
				}
			}
			
		</script>
</body>
</html>